<style scoped>

</style>
<template>
    <div class="change-PO-page">
        <el-form :inline="true" :model="changePOForm" ref="changePOForm" class="demo-form-inline" style="border-bottom:1px solid #ccc;">
            <el-form-item label="PO编号" :label-width="formLabelWidth">
                <el-input size="mini" disabled v-model="changePOForm.prOrderCode" placeholder="PO编号"></el-input>
            </el-form-item>
            <el-form-item label="制单日期" :label-width="formLabelWidth">
                <el-input size="mini" disabled v-model="changePOForm.createTime" placeholder="当前系统日期"></el-input>
            </el-form-item>
            <el-form-item label="制单人" :label-width="formLabelWidth">
                <el-input size="mini" disabled v-model="changePOForm.creatorName" placeholder="当前登录系统人员信息"></el-input>
            </el-form-item>
            <el-form-item label="采购类别" prop="procurementCategory" :rules="[{ required: true, message: '采购类别不能为空'}]" :label-width="formLabelWidth">
                <el-select size="mini"  v-model="changePOForm.procurementCategory" placeholder="请选择" @change="selectedProcurementCategory">
                    <el-option v-for="(procurementCategory,index) in changePOForm.procurementCategorys" :key="index" :label="procurementCategory.label" :value="procurementCategory.value"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="紧急程度" prop="emergencyDegree" :rules="[{ required: true, message: '紧急程度不能为空'}]" :label-width="formLabelWidth">
                <el-select size="mini"  v-model="changePOForm.emergencyDegree" placeholder="请选择">
                    <el-option v-for="(emergencyDegree,index) in changePOForm.emergencyDegrees" :key="index" :label="emergencyDegree.label" :value="emergencyDegree.value"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="采购合同号" :label-width="formLabelWidth">
                <el-input size="mini" disabled v-model="changePOForm.contractNo" placeholder="请输入采购合同号"></el-input>
            </el-form-item>
            <el-form-item label="采购单位" :label-width="formLabelWidth">
                <el-input size="mini" disabled v-model="changePOForm.poLegalPersonName" placeholder="请输入采购单位"></el-input>
                <!-- 
                <el-select size="mini"  v-model="changePOForm.poLegalPerson">
                    <el-option v-for="legalPerson in legalPersonDropDown" :label="legalPerson.legalPersonName" :value="legalPerson.legalPersonName"></el-option>
                </el-select>
                -->
            </el-form-item>
            <el-form-item label="收货工厂" prop="legalPlant"  :rules="[{ required: true, message: '收货工厂不能为空'}]" :label-width="formLabelWidth">
                <el-select size="mini"  v-model="changePOForm.legalPlant" placeholder="请选择">
                    <el-option v-for="(legalPlant,index) in changePOForm.legalPlants" :key="index" :label="legalPlant" :value="legalPlant"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="期望到货日期" prop="expectTime"  :rules="[{ required: true, message: '期望到货日期不能为空'}]" :label-width="formLabelWidth100">
                <el-date-picker type="date" size="mini" :editable="false"  v-model="changePOForm.expectTime" placeholder="选择日期" @change="selectedExpectTime"></el-date-picker>
            </el-form-item>
            <el-form-item label="供应商" :label-width="formLabelWidth">
                <el-input size="mini" disabled v-model="changePOForm.partnerName" placeholder="请输入采购单位"></el-input>
                <!-- 
                <el-select size="mini"  v-model="changePOForm.partnerName">
                    <el-option v-for="partner in changePOForm.partner" :label="partner.partnerName" :value="partner.partnerCode"></el-option>
                </el-select>
                -->
            </el-form-item>
            <el-form-item label="发货工厂" prop="sendPlant"  :rules="[{ required: true, message: '发货工厂不能为空'}]" :label-width="formLabelWidth">
                <el-input size="mini" v-model.trim="changePOForm.sendPlant" placeholder=""></el-input>
                <!-- 
                <el-select size="mini"  v-model="changePOForm.sendPlant" placeholder="请选择">
                    <el-option v-for="sendPlant in changePOForm.sendPlant" :label="sendPlant.label" :value="sendPlant.value"></el-option>
                </el-select>
                -->
            </el-form-item>
            <el-form-item label="联系人" :label-width="formLabelWidth">
                <el-input size="mini"  v-model="changePOForm.contacts" placeholder="请输入联系人"></el-input>
            </el-form-item>
            <el-form-item label="联系方式" :label-width="formLabelWidth">
                <el-input size="mini"  v-model="changePOForm.telephone" placeholder="请输入联系方式"></el-input>
            </el-form-item>
            <el-form-item label="币别" prop="currency" :rules="[{ required: true, message: '币别不能为空'}]" :label-width="formLabelWidth">
                <el-select size="mini"  v-model="changePOForm.currency" placeholder="请选择" @change="selectedCurrency">
                    <el-option v-for="(currencyType,index) in changePOForm.currencyTypes" :key="index" :label="currencyType.label" :value="currencyType.value"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="汇率" :label-width="formLabelWidth" prop="exRate" :rules="[{ required: true, message: '汇率不能为空'}]">
                <el-input size="mini"  v-model.trim="changePOForm.exRate" placeholder="请输入汇率" @change="inputExRate"></el-input>
            </el-form-item>
            <el-form-item label="结算方式" prop="settlementMethod" :rules="[{ required: true, message: '结算方式不能为空'}]"  :label-width="formLabelWidth">
                <el-select size="mini"  v-model="changePOForm.settlementMethod" placeholder="请选择">
                    <el-option v-for="(settlementMethod,index) in changePOForm.settlementMethods" :key="index" :label="settlementMethod.label" :value="settlementMethod.value"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="账期计算方法" prop="calculationType" :rules="[{ required: true, message: '账期计算方法不能为空'}]" :label-width="formLabelWidth100">
                <el-select size="mini"  v-model="changePOForm.calculationType" placeholder="请选择">
                    <el-option v-for="(calculationType,index) in changePOForm.calculationTypes" :key="index" :label="calculationType.label" :value="calculationType.value"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="账期" prop="billPeriods" :rules="[{ required: true, message: '账期不能为空'}]" :label-width="formLabelWidth">
                <el-input size="mini"  v-model.trim="changePOForm.billPeriods" placeholder="请输入账期(以天为单位)"></el-input>
            </el-form-item>
            <el-form-item label="采购含税总金额" :label-width="formLabelWidth120">
                <el-input size="mini" disabled v-model="changePOForm.totalMoney" placeholder=""></el-input>
            </el-form-item>
            <el-form-item label="采购不含税总金额" :label-width="formLabelWidth120">
                <el-input size="mini" disabled v-model="changePOForm.totalMoneyNoTax" placeholder=""></el-input>
            </el-form-item>
            <el-form-item label="本币含税总金额" :label-width="formLabelWidth120">
                <el-input size="mini" disabled v-model="changePOForm.currencyTotalMoney" placeholder=""></el-input>
            </el-form-item>
            <el-form-item label="本币不含税总金额" :label-width="formLabelWidth120">
                <el-input size="mini" disabled v-model="changePOForm.currencyTotalMoneyNoTax" placeholder=""></el-input>
            </el-form-item>
            <el-form-item>
                <el-checkbox v-model="singleDeliveryAddress" @change="handleSAddress">仅单一确定的收货地址</el-checkbox>

                <el-checkbox v-if="taxCodeTaxRateFlag" v-model="inputPriceWithoutTax" @change="changeIsTax">填写不含税价格</el-checkbox>
                <el-checkbox v-else disabled v-model="inputPriceWithoutTax">填写不含税价格</el-checkbox>
            </el-form-item>
            <el-form-item  label="税率"  v-if="taxCodeTaxRateFlag">
                <el-select size="mini"   v-model="changePOForm.taxCode" placeholder="请选择" @change="selectedAllTaxCode">
                    <el-option v-for="(taxCode,index) in changePOForm.taxCodeSelector" :key="index" :label="taxCode.label" :value="taxCode.value"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="备注">
                <el-input size="mini" type="text" autosize v-model="changePOForm.remarks" placeholder="请输入备注"></el-input>
            </el-form-item>
            <el-form-item> 
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="savePO">保存</el-button>
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" v-if="changePOForm.status == 'SAVE' ||changePOForm.status == 'LOCAL_SAVED' || changePOForm.status == 'SAVED_IG_NO'  || changePOForm.status == 'REVIEW_REJECTED' || changePOForm.status == 'EXAMINE_REJECTED'" @click="submitPO">提交</el-button>
                <!-- 
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" v-if="changePOForm.status == 'SUBMITTED_IG_SUCCEED'" @click="handleReview">审核</el-button>
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" v-if="changePOForm.status == 'REVIEW_APPROVED_IG_SUCCEED'" @click="handleApprove">审批</el-button>
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" v-if="changePOForm.status == 'REVIEW_IG_FAIL' ||changePOForm.status == 'EXAMINE_IG_FAIL' || changePOForm.status == 'EXAMINE_REJECTED' ||changePOForm.status == 'REVIEW_REJECTED' ||changePOForm.status == 'SAVED_IG_NO'" @click="handleRemove">作废</el-button>
                -->
            </el-form-item>
        </el-form>
        <!--采购明细表格-->
        <label class="default-label">采购明细：</label>
        <el-table :data="procurementDetailsData" border style="width: 100%;" v-loading.body="loading" element-loading-text="拼命加载中">
            <el-table-column type="index" header-align="center" align="center" label="序"  width="40"></el-table-column>
            <el-table-column label="操作" header-align="center" align="center" width="80" type="danger">
                <template scope="scope">
                    <div class="operationItem bolder" @click="handleDel(scope.$index, scope.row)" >删除</div>
                </template>
            </el-table-column>
            <el-table-column prop="materialCode" label="备件编码" header-align="center" show-overflow-tooltip></el-table-column>
            <el-table-column prop="materialName" label="备件名称" header-align="center" show-overflow-tooltip></el-table-column>
            <el-table-column prop="standard" label="规格" header-align="center" show-overflow-tooltip></el-table-column>
            <el-table-column prop="unit" label="单位" header-align="center" width="80" show-overflow-tooltip></el-table-column>
            <el-table-column prop="amount" label="数量" header-align="center" width="80">
                 <template scope="scope">
                    <el-button size="mini" @click="quantityDetails(scope.$index, scope.row)"  class="blueFont">
                        {{scope.row.amount}}
                    </el-button>
                </template>
            </el-table-column>
            <el-table-column prop="priceWithTax" label="含税单价" header-align="center" align="right">
                <template scope="scope">
                    <el-input v-if="inputPriceWithoutTax == false" size="mini"  v-model.number="scope.row.priceWithTax" placeholder="请输入" @change="taxIncludedPrice(scope.$index, scope.row,$event)"></el-input>
                    <el-input v-else disabled size="mini"  v-model.number="scope.row.priceWithTax" placeholder=""   @change="taxIncludedPrice(scope.$index, scope.row,$event)"></el-input>
                </template>
            </el-table-column>
            <el-table-column prop="priceNoTax" label="不含税单价" header-align="center" align="right">
                 <template scope="scope">
                    <el-input v-if="inputPriceWithoutTax == true" size="mini"  v-model.number="scope.row.priceNoTax" placeholder="请输入" @change="unitPriceWithoutTax(scope.$index, scope.row,$event)"></el-input>
                    <el-input v-else disabled size="mini"  v-model.number="scope.row.priceNoTax" placeholder=""  @change="unitPriceWithoutTax(scope.$index, scope.row,$event)"></el-input>
                </template>
            </el-table-column>
            <el-table-column prop="taxCode" label="税码" header-align="center">
                 <template scope="scope">
                    <el-input size="mini"   v-if="taxCodeTaxRateFlag == false" disabled v-model="scope.row.taxCode" placeholder=""></el-input>
                    <el-select size="mini" v-else v-model="scope.row.taxCode" placeholder="请选择" @change="selectTaxRate">
                        <el-option v-for="(taxCode,index) in scope.row.taxCodes" :key="index" :label="taxCode.value" :value="taxCode.value"></el-option>
                    </el-select>
                </template>
            </el-table-column>
            <el-table-column prop="taxRate" label="税率(%)" header-align="center"></el-table-column>
            <el-table-column prop="totalNoTax" label="不含税总金额" header-align="center" align="right"></el-table-column>
            <el-table-column prop="tax" label="税额" header-align="center" align="right"></el-table-column>
            <el-table-column prop="totalMoney" label="含税总金额" header-align="center" align="right"></el-table-column>
            <el-table-column prop="currencyWord" label="币别" header-align="center" width="80" show-overflow-tooltip></el-table-column>
            <el-table-column prop="exRate" label="汇率" header-align="center" width="80"></el-table-column>
        </el-table>
        <!-- 收货明细弹窗 -->
        <!--<el-dialog title="收货明细" :visible.sync="receivingInformationVisible" :lock-scroll="false">-->
            <div v-if="receivingInformationVisible">
                <label>收货明细：</label>
                <el-button type="danger" class="bolder" size="mini"  @click="addStorageRoom()" >新增</el-button>
                <el-table :data="receivingInformationDate" border style="margin-top:16px;width: 100%;">
                    <el-table-column type="index" header-align="center" align="center" label="序"  width="40"></el-table-column>
                    <el-table-column label="操作" header-align="center" align="center" width="80">
                        <template scope="scope">
                            <div class="operationItem bolder" @click="deleteReceivingInformation(scope.$index, receivingInformationDate)" >删除</div>
                        </template>
                    </el-table-column>
                    <el-table-column prop="storeRoomName" label="仓库名称" header-align="center" show-overflow-tooltip></el-table-column>
                    <el-table-column prop="storeRoomAdress" label="地址" header-align="center" show-overflow-tooltip></el-table-column>
                    <el-table-column prop="linkMan" label="联系人" header-align="center" show-overflow-tooltip></el-table-column>
                    <el-table-column prop="linkManMobile" label="联系电话" header-align="center" show-overflow-tooltip></el-table-column>
                </el-table>
            </div>

        <!--</el-dialog>-->
        <!-- 选择库房的弹窗 -->
          <el-dialog title="选择库房" :visible.sync="selectStorageRoomVisible" :lock-scroll="false">
            <el-form :model="chooseStorageRoomForm" :inline="true">
                <el-form-item label="库房编号:" >
                    <el-input size="mini" v-model="chooseStorageRoomForm.storageRoomCode" auto-complete="off" placeholder="请输入库房编号"></el-input>
                </el-form-item>
                <el-form-item label="库房名称:" >
                    <el-input size="mini" v-model="chooseStorageRoomForm.storageRoomName" auto-complete="off" placeholder="请输入库房名称"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="danger" class="bolder outsideBtnBS selectAll" :disabled="selectDisabled" size="mini" @click="queryStorageRoom">查询</el-button>
                    <el-button type="danger" class="bolder outsideBtnBS" size="mini" @click="insertStorageRoom">确定</el-button>
                </el-form-item>
            </el-form>
            <el-table :data="storageRoomDate" border style="margin-top:16px;width: 100%;" v-loading.body="loading" element-loading-text="拼命加载中">
                <el-table-column type="index" header-align="center" align="center" label="序"  width="40"></el-table-column>
                <el-table-column label="选择" header-align="center" align="center" width="40">
                    <template scope="scope">
                        <el-checkbox size="mini" @change="checkedStorageRoom(scope.$index, scope.row,$event)"></el-checkbox>
                    </template>
                </el-table-column>
                <el-table-column prop="storeRoomCode" label="库房编号" header-align="center" show-overflow-tooltip></el-table-column>
                <el-table-column prop="storeRoomName" label="库房名称" header-align="center" show-overflow-tooltip></el-table-column>
            </el-table>
        </el-dialog>
        <!-- 点击数量查看PO执行明细信息 执行明细弹窗 -->
        <el-dialog title="明细" :visible.sync="quantityDetailsVisible" size="large" :closeOnClickModal="false" :showClose="false" :lock-scroll="false">
            <el-table :data="quantityDetailsData" border style="width: 100%">
                <el-table-column type="index" header-align="center" align="center" label="序"  width="40"></el-table-column>
                <el-table-column property="planCode" label="计划编号" header-align="center" show-overflow-tooltip></el-table-column>
                <el-table-column property="materialCode" label="备件编码" header-align="center" show-overflow-tooltip></el-table-column>
                <el-table-column property="materialName" label="备件名称" header-align="center" show-overflow-tooltip></el-table-column>
                <el-table-column property="standard" label="规格" header-align="center" show-overflow-tooltip></el-table-column>
                <el-table-column property="unit" label="计量单位" header-align="center" show-overflow-tooltip></el-table-column>
                <el-table-column property="planAmount" label="计划数量" header-align="center"></el-table-column>
                <el-table-column property="leftAmount" label="未采购数量" header-align="center"></el-table-column>
                <el-table-column property="excuteAmount" label="本次采购数量" header-align="center">
                    <template scope="scope">
                        <el-input size="mini" class="excuteAmount" v-model.number="scope.row.excuteAmount"  @change="quantityPurchased(scope.$index, scope.row,$event)"></el-input>
                    </template>
                </el-table-column>
            </el-table>
            <span slot="footer" class="dialog-footer">
                <el-button class="bolder outsideBtnBS" @click="handleCancel()" size="mini">取消</el-button>
	            <el-button class="bolder outsideBtnBS" @click="handleComfirm()" size="mini" type="danger">确定</el-button>
            </span>
        </el-dialog>
        <!-- 点击审核 审核弹窗 
        <el-dialog title="审核提示信息" :visible.sync="handleReviewVisible" size="small" :lock-scroll="false">
            <el-form :model="reviewForm">
                <h2>是否审核通过当前单据？</h2>
                <el-form-item label="审核意见" :label-width="formLabelWidth">
                    <el-input type="textarea"  :rows="3" placeholder="请输入内容" v-model="reviewForm.textarea">
                    </el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="toExamine(true)">审核通过</el-button>
                <el-button @click="toExamine(false)">审核不通过</el-button>
            </div>
        </el-dialog>-->
        <!-- 点击审批 审批弹窗 
        <el-dialog id="approvalMask" title="审批提示信息" :visible.sync="handleApprovalVisible" size="small" :lock-scroll="false">
            <el-form :model="approvalForm">
                <h2>是否审批通过当前单据？</h2>
                <el-form-item label="审批意见" :label-width="formLabelWidth">
                    <el-input type="textarea"  :rows="3" placeholder="请输入内容" v-model="approvalForm.textarea">
                    </el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="examinationAndApproval(true)">审批通过</el-button>
                <el-button @click="examinationAndApproval(false)">审批不通过</el-button>
            </div>
        </el-dialog>-->
    </div>
</template>


<script>

    export default {
        data() {
            return {
                // 查询表单
                changePOForm:{
                    prOrderCode:"", // po编号
                    procurementCategory:"",   // 采购方式
                    emergencyDegree: "",
                    currency: "",
                    currencyWord:"",
                    settlementMethod: "",
                    calculationType: "",
                    creatorName: "",
                    creatorId: "",
                    partnerId: "",//供应商
                    partnerCode: "",
                    partnerName: "",
                    legalPersonCode: "",
                    legalPersonName: "",
                    contractNo: "",
                    expectTime: "",
                    sendPlant: "",
                    contacts: "",
                    telephone: "",
                    billPeriods: "",
                    amount: "",
                    totalMoney: "",
                    poLegalPersonName:"",   //采购单位
                    poLegalPersonCode:"",  //采购单位
                    legalPlant:"",    //收货工厂
                    taxCodeSelector:"",    //税码下拉列表
                    taxCode:"",  //税码
                },   
                poSaveBasicParam:{},   //保存时对应的changePOForm的值
                singleDeliveryAddress:false,    // 仅单一确定的收货地址(true)
                inputPriceWithoutTax:true,    //填写不含税单价(true 默认填写)   
                procurementCategoryFlag: false,   // 根据采购类别(国际采购或者同法人转储) 税码税率不必填 
                taxCodeTaxRateFlag:true,   // 综合判断决定税码税率可编辑为true     不可编辑false    
                legalPersonDropDown:[],
                loading:false,
                procurementDetailsData: [],// 采购明细表格
                selectDropdown:[],  // 下拉列表的值
                spareData:[],
                formLabelWidth:"80px",
                formLabelWidth100:"100px",
                formLabelWidth120:"120px",
                receivingInformationVisible:false,   //收货信息的弹窗不可见
                receivingInformationDate:[],    //收货信息 表格 
                chooseStorageRoomForm:{     //查询库房的条件
                    storageRoomCode:"",
                    storageRoomName:"",
                },
                selectStorageRoomVisible:false,   //选择库房的弹窗不可见
                storageRoomDate:[],   //库房信息的表格
                checkedStorageRoomDate:[],    //选中的库房的信息
                // handleReviewVisible:false,    //审核弹窗
                // reviewForm:{      //审核内容
                //     textarea:""
                // },
                // handleApprovalVisible:false,    // 审批弹窗
                // approvalForm:{      //审批内容
                //     textarea:""
                // },
                deletedProcurementOrderItems:[],//选中删除

                quantityDetailsVisible:false,    //点击每行的数量 明细弹窗
                quantityDetailsData:[],    //点击每行的数量 明细弹窗中的数据
                //查询禁用
                selectDisabled:false,

                storageAmount:0,   //存储数量
                
                storgeTrueAmount:[],    //存储正确的本次采购数量
                storegePlanAggregationItemId:""   //存储关联id
            };
        },
        //进入页面立即运行此方法
        mounted: function () {
            var _this = this;
            _this.$store.commit('currentActive', 'ChangePO');
            // //ajax前后查询按钮禁用
            // $(".selectAll").ajaxStart(function(){
            //     _this.selectDisabled=true;
            // });
            // $(".selectAll").ajaxStop(function(){
            //     _this.selectDisabled=false;
            // });
             _this.changePOForm.prOrderCode=_this.$route.query.prOrderCode;
            
            _this.changePOGetData();  //进入页面直接传值调接口  修改po时该带出来的值
        },
        methods: {
            changePOGetData(){   //进入页面直接传值调接口  修改po时该带出来的值
                var _this =this;
                $.ajax({
                    url:_this.procurement_service+'procurementOrder/toUpdate?prOrderCode='+_this.changePOForm.prOrderCode,
                    type:'POST',
                    cache:false,
                    // data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType:'application/json;charset=utf-8',
                    success:function(data){
                        if(data.success){
                            // 判断采购类别
                            if(data.data.procurementOrderBasic.procurementCategory == 'NA'){
                                _this.procurementCategoryFlag = true;   // 根据采购类别 税码税率必填
                            }else{
                                _this.procurementCategoryFlag = false;   //  根据采购类别 税码税率不必填
                                _this.inputPriceWithoutTax = true; // 填写不含税单价(true 默认填写)  
                            }
                            _this.judgeTaxCodeTaxRate();

                            //'仅单一确定的收货地址'
                            _this.singleDeliveryAddress=data.data.procurementOrderBasic.hasSingleAddr;
                            _this.receivingInformationVisible=data.data.procurementOrderBasic.hasSingleAddr;
                            // 库房信息
                            if(data.data.storeRoom){
                                _this.receivingInformationDate.push(data.data.storeRoom);
                            }
                            //'填写不含税单价'为NO时，应为选中状态
                            if(data.data.procurementOrderBasic.withTaxFlag == 'NO'){
                                _this.inputPriceWithoutTax = true;
                            }else if(data.data.procurementOrderBasic.withTaxFlag == 'YES'){
                                _this.inputPriceWithoutTax = false;
                            }
                            
                            
                            data.data.procurementOrderBasic.taxCode="";
                            data.data.procurementOrderBasic.taxRate="";
                            _this.changePOForm=data.data.procurementOrderBasic;

                            if(_this.changePOForm.totalMoney!=null){
                                _this.changePOForm.totalMoney = _this.changePOForm.totalMoney.toFixed(2);   //采购含税总金额保留两位小数totalMoneyNoTax
                            }
                            if(_this.changePOForm.totalMoneyNoTax!=null){
                                _this.changePOForm.totalMoneyNoTax = _this.changePOForm.totalMoneyNoTax.toFixed(2);   //采购不含税总金额保留两位小数
                            }
                            if(_this.changePOForm.currencyTotalMoney!=null){
                                _this.changePOForm.currencyTotalMoney = _this.changePOForm.currencyTotalMoney.toFixed(2);   //本币含税总金额保留两位小数
                            }
                            if(_this.changePOForm.currencyTotalMoneyNoTax!=null){
                                _this.changePOForm.currencyTotalMoneyNoTax = _this.changePOForm.currencyTotalMoneyNoTax.toFixed(2);   //本币不含税总金额保留两位小数
                            }
                            _this.changePOForm.creator=data.data.procurementOrderBasic.creator;   // 制单人
                            for(var key in _this.changePOForm.creator){
                                _this.changePOForm.creatorId = key;
                                _this.changePOForm.creatorName = _this.changePOForm.poLegalPerson[key];
                            }
                            _this.changePOForm.poLegalPersonCode = data.data.procurementOrderBasic.legalPersonCode;    
                            _this.changePOForm.poLegalPersonName = data.data.procurementOrderBasic.legalPersonName;
                            //添加币别名称字段
                            for(var i=0;i<data.data.procurementOrderItems.length;i++){
                                data.data.procurementOrderItems[i].currencyWord="";
                            }
                            _this.procurementDetailsData=data.data.procurementOrderItems;
                            // // 税码和税率------------------
                            // for(var i=0;i<_this.procurementDetailsData.length;i++){  
                            //     var taxCodes=_this.procurementDetailsData[i].taxCodes;
                            //     // console.log(taxCodes);
                            //     _this.procurementDetailsData[i].taxCodes=[];
                            //     for(var key in taxCodes[i]){
                            //         _this.procurementDetailsData[i].taxCodes.push({
                            //             taxCode:key,
                            //             taxRate:taxCodes[i][key]
                            //         });
                            //     }
                            // }
                            for(var i=0;i<_this.procurementDetailsData.length;i++){  
                                _this.procurementDetailsData[i].taxCodes = _this.changePOForm.taxCodeSelector;// 税码税率
                                // _this.procurementDetailsData[i].taxCodes = _this.procurementDetailsData[0].taxCodes;
                            
                                if(_this.procurementDetailsData[i].priceWithTax != null){
                                    _this.procurementDetailsData[i].priceWithTax=_this.procurementDetailsData[i].priceWithTax.toFixed(8);  //含税单价保留八位小数
                                }
                                if(_this.procurementDetailsData[i].priceNoTax != null){
                                    _this.procurementDetailsData[i].priceNoTax=_this.procurementDetailsData[i].priceNoTax.toFixed(8);  //不含税单价保留八位小数
                                }
                                if(_this.procurementDetailsData[i].tax != null){
                                    _this.procurementDetailsData[i].tax=_this.procurementDetailsData[i].tax.toFixed(2);   //税额保留两位小数
                                }
                                if(_this.procurementDetailsData[i].totalNoTax != null){
                                    _this.procurementDetailsData[i].totalNoTax=_this.procurementDetailsData[i].totalNoTax.toFixed(2);   //不含税总金额保留两位小数
                                }
                                if(_this.procurementDetailsData[i].totalMoney != null){
                                    _this.procurementDetailsData[i].totalMoney=_this.procurementDetailsData[i].totalMoney.toFixed(2);   //含税总金额保留两位小数
                                }                                
                            }
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                })
            },
            //期望到货日期
            selectedExpectTime(val){
                var _this=this;
                _this.changePOForm.expectTime = val;
            },
            // 选择采购类别
            selectedProcurementCategory(){
                var _this=this; 
                // 采购类别为普通采购或者跨法人转储时，‘填写不含税单价’可选可不选，但是税码、税率必填
                // 采购类别为国际采购或者同法人转储时，‘填写不含税单价’必选，税码、税率不可编辑、含税相关的都为0
                if(_this.changePOForm.procurementCategory == 'NA'){
                    _this.procurementCategoryFlag = true;   // 根据采购类别 税码税率必填
                }else{
                    _this.procurementCategoryFlag = false;   //  根据采购类别 税码税率不必填
                    _this.inputPriceWithoutTax = true; // 填写不含税单价(true 默认填写)  
                }
                _this.judgeTaxCodeTaxRate();
            },
            // 根据采购类型及 选不选中‘填写不含税单价’来确定 税码税率填写不填写
            judgeTaxCodeTaxRate(){
                var _this=this;
                if(!_this.procurementCategoryFlag){
                    _this.taxCodeTaxRateFlag =false; // 综合判断决定税码税率可编辑为true     不可编辑false 
                    _this.handleDisableNoTaxPrice();
                }else{
                    _this.taxCodeTaxRateFlag =true;
                }
            },
            // "填写不含税价格"不可修改时   含税的都清空
            handleDisableNoTaxPrice(){
                var _this=this;
                var arr=_this.procurementDetailsData;
                for(var i=0;i<arr.length;i++){
                    arr[i].priceWithTax = ""; //含税单价
                    arr[i].taxCode=""; //税码
                    arr[i].taxRate=""; //税率

                    arr[i].totalMoney=0.00;  // 含税总金额总金额
                    arr[i].tax=0.00;  //税额
                }
                _this.changePOForm.totalMoney=0.00;  //采购含税总金额   
                _this.changePOForm.currencyTotalMoney=0.00; //本币含税总金额   

                _this.changePOForm.taxCode = "";   //税码
                _this.changePOForm.taxRate = "";   //税率 
            },
            //选择所有税码 税率
            selectedAllTaxCode(){
                var _this=this;
                for(var i=0;i<_this.changePOForm.taxCodeSelector.length;i++){
                    if(_this.changePOForm.taxCode == _this.changePOForm.taxCodeSelector[i].value){
                        _this.changePOForm.taxRate = _this.changePOForm.taxCodeSelector[i].label;
                        // 给所有的行项目赋值
                        for(var  j=0;j<_this.procurementDetailsData.length;j++){
                            _this.procurementDetailsData[j].taxCodes = _this.changePOForm.taxCodeSelector;
                            _this.procurementDetailsData[j].taxCode = _this.changePOForm.taxCode;
                            _this.procurementDetailsData[j].taxRate = _this.changePOForm.taxRate;
                        }
                    }
                }
            },
            // 选择税码  带出税率
            selectTaxRate(){
                var _this=this;
                for(var i=0;i<_this.procurementDetailsData.length;i++){
                    for(var j=0;j<_this.procurementDetailsData[i].taxCodes.length;j++){
                         if(_this.procurementDetailsData[i].taxCode == _this.procurementDetailsData[i].taxCodes[j].value){
                            _this.procurementDetailsData[i].taxRate = _this.procurementDetailsData[i].taxCodes[j].label;

                            if(_this.inputPriceWithoutTax){ // 填写不含税单价(true 默认填写)
                                _this.procurementDetailsData[i].priceNoTax = Number(_this.procurementDetailsData[i].priceNoTax).toFixed(8);
                                _this.procurementDetailsData[i].priceWithTax=(_this.procurementDetailsData[i].priceNoTax*(1+_this.procurementDetailsData[i].taxRate/100)).toFixed(8);//计算含税单价=不含税单价金额＊（1+税率）
                            }else{
                                _this.procurementDetailsData[i].priceWithTax = Number(_this.procurementDetailsData[i].priceWithTax).toFixed(8);
                                _this.procurementDetailsData[i].priceNoTax = (_this.procurementDetailsData[i].priceWithTax / (1 + _this.procurementDetailsData[i].taxRate / 100)).toFixed(8);//计算不含税单价金额=含税单价金额/（1+税率）
                            }

                            _this.procurementDetailsData[i].totalNoTax = (_this.procurementDetailsData[i].priceNoTax * _this.procurementDetailsData[i].amount).toFixed(2);  //不含税总金额=不含税单价*数量；不含税总金额最多只能有两位小数
                            _this.procurementDetailsData[i].tax =  (_this.procurementDetailsData[i].priceNoTax * _this.procurementDetailsData[i].amount * _this.procurementDetailsData[i].taxRate/100).toFixed(2);  //税额=不含税单价*数量*税率；税额最多只能有两位小数
                            _this.procurementDetailsData[i].totalMoney = (_this.procurementDetailsData[i].priceWithTax * _this.procurementDetailsData[i].amount).toFixed(2);  //总金额=含税单价*数量；总金额最多只能有两位小数
                        }
                    }
                }
                _this.calTotalMoney(); //采购含税总金额、采购不含税金额
                _this.inputExRate(); // 表单中的本币含税总金额 = 总金额 * 汇率
            },
            // 输入汇率
            inputExRate(){ // 表单中的本币含税总金额 = 总金额 * 汇率
                var _this=this;
                for(var i=0;i<_this.procurementDetailsData.length;i++){
                    _this.procurementDetailsData[i].exRate = _this.changePOForm.exRate;
                }
                _this.changePOForm.currencyTotalMoney = (_this.changePOForm.totalMoney * _this.changePOForm.exRate).toFixed(2);   //本币含税总金额
                _this.changePOForm.currencyTotalMoneyNoTax = (_this.changePOForm.totalMoneyNoTax * _this.changePOForm.exRate).toFixed(2);   //本币不含税总金额
            },
            // 采购含税总金额、采购不含税总金额的计算
            calTotalMoney(){
                var _this=this; 
                var allTotalMoney=0,allTotalMoneyNoTax=0;
                for(var i=0;i<_this.procurementDetailsData.length;i++){
                    allTotalMoney += Number(_this.procurementDetailsData[i].totalMoney);
                    allTotalMoneyNoTax += Number(_this.procurementDetailsData[i].totalNoTax);
                }
                _this.changePOForm.totalMoney=allTotalMoney.toFixed(2);//采购含税总金额
                _this.changePOForm.totalMoneyNoTax=allTotalMoneyNoTax.toFixed(2);//采购不含税总金额
            },
            // 从下拉列表中选择币别
            selectedCurrency(){
                var _this=this;
                for(var i=0;i<_this.changePOForm.currencyTypes.length;i++){
                    if(_this.changePOForm.currency == _this.changePOForm.currencyTypes[i].value){
                        _this.changePOForm.currencyWord = _this.changePOForm.currencyTypes[i].label;
                    }
                }
                for(var i=0;i<_this.procurementDetailsData.length;i++){
                    _this.procurementDetailsData[i].currency = _this.changePOForm.currency;
                    _this.procurementDetailsData[i].currencyWord = _this.changePOForm.currencyWord;
                }
            },
            // 切换“填写不含税单价”
            changeIsTax(){
                var _this=this;
                var arr=_this.procurementDetailsData;
                for(var i=0;i<arr.length;i++){
                    arr[i].priceWithTax = ""; //含税单价
                    arr[i].priceNoTax="";//不含税单价
                    arr[i].taxCode=""; //税码
                    arr[i].taxRate=""; //税率

                    arr[i].totalMoney=0.00;  // 总金额
                    arr[i].totalNoTax=0.00;  //不含税总金额
                    arr[i].tax=0.00;  //税额
                }
                _this.changePOForm.totalMoney=0.00;  //采购含税总金额   
                _this.changePOForm.totalMoneyNoTax=0.00;  //采购不含税总金额
                _this.changePOForm.currencyTotalMoney=0.00; //本币含税总金额 
                _this.changePOForm.currencyTotalMoneyNoTax=0.00; //本币不含税总金额             
            },
            // 输入含税价格  联动的计算
            taxIncludedPrice(index,row,event){
                var _this=this;
                if(typeof(row.priceWithTax) != 'number'){
                    _this.common.errorTip("请输入数字类型！");
                    row.priceWithTax = 0;
                }else{
                    row.totalMoney = (row.priceWithTax * row.amount).toFixed(2);  //含税总金额=含税单价*数量；总金额最多只能有两位小数
                    row.priceNoTax = (row.priceWithTax / (1 + row.taxRate / 100)).toFixed(8);//计算不含税单价金额=含税单价金额/（1+税率）     
                    //联动不含税单价相关的计算
                    row.totalNoTax = (row.priceNoTax * row.amount).toFixed(2);  //不含税总金额=不含税单价*数量；不含税总金额最多只能有两位小数
                    row.tax =  (row.priceNoTax * row.amount * row.taxRate/100).toFixed(2);  //税额=不含税单价*数量*税率；税额最多只能有两位小数

                    _this.calTotalMoney(); //采购含税总金额、采购不含税金额
                    _this.inputExRate(); // 表单中的本币含税总金额 = 总金额 * 汇率
                }
            },
            //输入不含税单价 联动计算
            unitPriceWithoutTax(index,row,event){
                var _this=this;
                if(typeof(row.priceNoTax) != 'number'){
                    _this.common.errorTip("请输入数字类型！");
                    row.priceNoTax=0;
                }else{
                    row.totalNoTax = (row.priceNoTax * row.amount).toFixed(2);  //不含税总金额=不含税单价*数量；不含税总金额最多只能有两位小数
                    if(_this.taxCodeTaxRateFlag){    // 税码税率可编辑 才算与税相关的
                        row.tax = (row.priceNoTax * row.amount * row.taxRate/100).toFixed(2);  //税额=不含税单价*数量*税率；税额最多只能有两位小数
                        row.priceWithTax=(row.priceNoTax*(1+row.taxRate/100)).toFixed(8);//计算含税单价=不含税总金额＊（1+税率）   
                        // 联动含税单价联动的计算                    
                        row.totalMoney = (row.priceWithTax * row.amount).toFixed(2);  //含税总金额=含税单价*数量；总金额最多只能有两位小数
                    }
                    _this.calTotalMoney(); //采购含税总金额、采购不含税金额   
                    _this.inputExRate(); // 表单中的本币含税总金额 = 总金额 * 汇率
                }
            },
            // 点击每行的数量 明细弹窗
            quantityDetails(index, row){
                var _this = this;
                _this.quantityDetailsVisible = true;
                _this.storegePlanAggregationItemId=row.planAggregationItemId;
                // _this.storgeOldAmount=row.amount; 
                _this.quantityDetailsData = row.poItemExcuteVos;
                _this.storgeTrueAmount=[];
                for(var i=0;i<_this.quantityDetailsData.length;i++){
                    if(_this.storegePlanAggregationItemId == _this.quantityDetailsData[i].planAggregationItemId){
                        _this.storgeTrueAmount.push(_this.quantityDetailsData[i].excuteAmount);
                    }
                }
            },
            // 输入本次采购数量
            quantityPurchased(index,row,event){
                var _this=this;
                row.excuteAmount = Number(row.excuteAmount);
                if(typeof(row.excuteAmount) != 'number'){
                    // row.excuteAmount = 0;
                    _this.common.errorTip("请输入数字类型！");
                }
                if(row.excuteAmount<0){
                    // row.excuteAmount = 0;
                    _this.common.errorTip("本次采购数量必须大于0！");
                }
                if(row.excuteAmount <= row.leftAmount){
                    // _this.storageAmount=0;
                    for(var j=0;j<_this.quantityDetailsData.length;j++){
                        if(_this.storegePlanAggregationItemId == _this.quantityDetailsData[j].planAggregationItemId){
                            _this.storageAmount += _this.quantityDetailsData[j].excuteAmount;
                        }
                    }
                }else{
                    // row.excuteAmount = 0;
                    _this.common.errorTip("本次采购数量不能大于未采购数量!");
                }
            },
            // 执行明细弹窗  确定按钮  验证本次采购数量
            handleComfirm(){
                var _this=this;
                _this.storageAmount=0;
                _this.storgeTrueAmount=[];
                var judgeQuabtityFlag = false;   //存在本次采购数量不符合要求
                for(var j=0;j<_this.quantityDetailsData.length;j++){
                    if(_this.storegePlanAggregationItemId == _this.quantityDetailsData[j].planAggregationItemId){
                        if(_this.quantityDetailsData[j].excuteAmount == 0 || _this.quantityDetailsData[j].excuteAmount > _this.quantityDetailsData[j].leftAmount){    
                            // 如果某一行的本次采购数量为0，则本次采购数量默认等于未采购数量
                            // 或者如果某一行的本次采购数量大于未采购数量，则本次采购数量默认等于未采购数量
                            // _this.quantityDetailsData[j].excuteAmount=_this.quantityDetailsData[j].leftAmount;
                            judgeQuabtityFlag = false;  //如果存在本次采购数量等于0 或者大于采购数量，则不能确定，弹窗不消失 
                        }else{
                            _this.storageAmount += _this.quantityDetailsData[j].excuteAmount;
                            _this.storgeTrueAmount.push(_this.quantityDetailsData[j].excuteAmount);
                            judgeQuabtityFlag=true;
                        }
                    }
                }
                // 赋值
                if(judgeQuabtityFlag){
                    for(var i=0;i<_this.procurementDetailsData.length;i++){
                        if(_this.procurementDetailsData[i].planAggregationItemId == _this.storegePlanAggregationItemId){
                            if(_this.storageAmount>0){
                                _this.procurementDetailsData[i].amount = _this.storageAmount;
                                
                                _this.procurementDetailsData[i].totalMoney = (_this.procurementDetailsData[i].priceWithTax * _this.procurementDetailsData[i].amount).toFixed(2);  //含税总金额=含税单价*数量；总金额最多只能有两位小数
                                //联动不含税单价相关的计算
                                _this.procurementDetailsData[i].totalNoTax = (_this.procurementDetailsData[i].priceNoTax * _this.procurementDetailsData[i].amount).toFixed(2);  //不含税总金额=不含税单价*数量；不含税总金额最多只能有两位小数
                                _this.procurementDetailsData[i].tax = (_this.procurementDetailsData[i].priceNoTax * _this.procurementDetailsData[i].amount * _this.procurementDetailsData[i].taxRate/100).toFixed(2);  //税额=不含税单价*数量*税率；税额最多只能有两位小数
                                _this.calTotalMoney(); //采购含税总金额、采购不含税金额
                                _this.inputExRate(); // 表单中的本币含税总金额 = 总金额 * 汇率
                            }
                            _this.quantityDetailsVisible = false;                  
                        }
                    }
                }else{
                    _this.common.errorTip("本次采购数量必须大于0且小于未采购数量！");
                }
                
            },
            // 执行明细弹窗 取消按钮 验证本次采购数量
            handleCancel(){
                var _this=this; 
                _this.quantityDetailsVisible = false;
                for(var j=0;j<_this.quantityDetailsData.length;j++){
                    if(_this.storegePlanAggregationItemId == _this.quantityDetailsData[j].planAggregationItemId){
                        _this.quantityDetailsData[j].excuteAmount = _this.storgeTrueAmount[j];
                    }
                }
            },
            //仅单一确定的收货地址 checkbox
            handleSAddress(){
                var _this=this;
                if(_this.singleDeliveryAddress){
                    _this.receivingInformationVisible=true;
                }else{
                    _this.receivingInformationVisible=false;
                    _this.receivingInformationDate = [];  //不显示同时清空
                }
            },
            // 收货明细弹窗中点击每条的删除
            deleteReceivingInformation(index,rows){
                rows.splice(index,1);
            },
            // 收货明细弹窗中的新增按钮
            addStorageRoom(){
                var _this=this; console.log(_this.changePOForm.poLegalPersonCode);
                _this.selectStorageRoomVisible=true;
                var tmp={"legalPersonCode":_this.changePOForm.poLegalPersonCode,pageIndex:1,pageSize:100}
                $.ajax({
                    url:_this.metadata_service+'storeRoom/findStoreRoomList',
                    type:'POST',
                    cache:false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType:'application/json;charset=utf-8',
                    success:function(data){
                        if(data.success){
                            _this.storageRoomDate=data.data.dataList;
                            _this.checkedStorageRoomDate = [];   //选中的库房为空
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                })
            },
            //库房信息 选择库房
            checkedStorageRoom(index,row,event){
                var _this=this;
                _this.checkedStorageRoomDate.push(row);
            },
            // 库房信息的弹窗中的查询
            queryStorageRoom(){

            },
            // 库房信息的弹窗中的确定
            insertStorageRoom(){
                var _this=this;
                _this.selectStorageRoomVisible=false;
                _this.receivingInformationDate = _this.checkedStorageRoomDate;
            },
            //保存按钮
            savePO(){
                var _this = this;  
                _this.$refs['changePOForm'].validate((valid) => {
                    if (valid) {
                        if(_this.inputPriceWithoutTax){
                            _this.changePOForm.withTaxFlag = 'NO';
                        }else{
                            _this.changePOForm.withTaxFlag = 'YES';
                        }
                        _this.poSaveBasicParam.prOrderCode = _this.changePOForm.prOrderCode;
                        _this.poSaveBasicParam.procurementCategory = _this.changePOForm.procurementCategory;
                        _this.poSaveBasicParam.emergencyDegree = _this.changePOForm.emergencyDegree;_this.poSaveBasicParam.currency = _this.changePOForm.currency;
                        _this.poSaveBasicParam.legalPlant = _this.changePOForm.legalPlant;
                        _this.poSaveBasicParam.settlementMethod = _this.changePOForm.settlementMethod;_this.poSaveBasicParam.calculationType = _this.changePOForm.calculationType;_this.poSaveBasicParam.creatorName = _this.changePOForm.creatorName;
                        _this.poSaveBasicParam.creatorId = _this.changePOForm.creatorId;
                        _this.poSaveBasicParam.partnerId = _this.changePOForm.partnerId;
                        _this.poSaveBasicParam.partnerCode = _this.changePOForm.partnerCode;
                        _this.poSaveBasicParam.partnerName = _this.changePOForm.partnerName;
                        _this.poSaveBasicParam.legalPersonCode = _this.changePOForm.poLegalPersonCode;
                        _this.poSaveBasicParam.legalPersonName = _this.changePOForm.poLegalPersonName;
                        _this.poSaveBasicParam.status = _this.changePOForm.status;
                        _this.poSaveBasicParam.contractNo = _this.changePOForm.contractNo;
                        _this.poSaveBasicParam.expectTime = _this.changePOForm.expectTime;
                        _this.poSaveBasicParam.sendPlant = _this.changePOForm.sendPlant;
                        _this.poSaveBasicParam.contacts = _this.changePOForm.contacts;
                        _this.poSaveBasicParam.telephone = _this.changePOForm.telephone;
                        _this.poSaveBasicParam.exRate = _this.changePOForm.exRate;
                        _this.poSaveBasicParam.billPeriods = _this.changePOForm.billPeriods;
                        _this.poSaveBasicParam.amount = _this.changePOForm.amount;
                        _this.poSaveBasicParam.totalMoney = _this.changePOForm.totalMoney;
                        _this.poSaveBasicParam.totalMoneyNoTax = _this.changePOForm.totalMoneyNoTax;
                        _this.poSaveBasicParam.currencyTotalMoney = _this.changePOForm.currencyTotalMoney;
                        _this.poSaveBasicParam.currencyTotalMoneyNoTax = _this.changePOForm.currencyTotalMoneyNoTax;
                        _this.poSaveBasicParam.hasSingleAddr = _this.singleDeliveryAddress;  // '仅单一确定的收货地址'
                        _this.poSaveBasicParam.withTaxFlag = _this.changePOForm.withTaxFlag;
                        _this.poSaveBasicParam.remarks = _this.changePOForm.remarks;  // 备注
                        if(_this.receivingInformationDate.length){
                            // _this.poSaveBasicParam.storeRoomCode = _this.storageRoomDate[0].storeRoomCode;
                            _this.poSaveBasicParam.storeRoomCode = _this.receivingInformationDate[0].storeRoomCode;
                        }
                        
                        if(_this.procurementDetailsData.length > 0){
                            if(_this.poSaveBasicParam.hasSingleAddr && !_this.receivingInformationDate.length){
                                _this.common.errorTip("收货明细不能为空！");
                            }else{
                                var tmp = {
                                    poSaveBasicParam:_this.poSaveBasicParam,
                                    poSaveItemsParam:_this.procurementDetailsData,
                                    deletedProcurementOrderItems:_this.deletedProcurementOrderItems,
                                };
                                $.ajax({
                                    url:_this.procurement_service+'procurementOrder/update',
                                    type:'POST',
                                    cache:false,
                                    data:JSON.stringify(tmp),
                                    dataType:'JSON',
                                    contentType:'application/json;charset=utf-8',
                                    success:function(data){
                                        if(data.success){
                                            _this.common.successTip("保存成功！");
                                        }else{
                                            _this.common.errorTip(data.errorMessage);
                                        }
                                    }
                                })
                            }
                        }else{
                            _this.common.errorTip("采购明细不能为空！");
                        }
                        
                    } else {
                        _this.common.errorTip("存在未填写的必填项！");
                        return false;
                    }
                });
            },
            //提交按钮
            submitPO(){
                var _this=this;
                _this.$refs['changePOForm'].validate((valid) => {
                    if (valid) {
                        if(_this.inputPriceWithoutTax){
                            _this.changePOForm.withTaxFlag = 'NO';
                        }else{
                            _this.changePOForm.withTaxFlag = 'YES';
                        }
                        _this.poSaveBasicParam.prOrderCode = _this.changePOForm.prOrderCode;
                        _this.poSaveBasicParam.procurementCategory = _this.changePOForm.procurementCategory;
                        _this.poSaveBasicParam.emergencyDegree = _this.changePOForm.emergencyDegree;
                        _this.poSaveBasicParam.currency = _this.changePOForm.currency;
                        _this.poSaveBasicParam.legalPlant = _this.changePOForm.legalPlant;
                        _this.poSaveBasicParam.settlementMethod = _this.changePOForm.settlementMethod;_this.poSaveBasicParam.calculationType = _this.changePOForm.calculationType;_this.poSaveBasicParam.creatorName = _this.changePOForm.creatorName;
                        _this.poSaveBasicParam.creatorId = _this.changePOForm.creatorId;
                        _this.poSaveBasicParam.partnerId = _this.changePOForm.partnerId;
                        _this.poSaveBasicParam.partnerCode = _this.changePOForm.partnerCode;
                        _this.poSaveBasicParam.partnerName = _this.changePOForm.partnerName;
                        _this.poSaveBasicParam.legalPersonCode = _this.changePOForm.poLegalPersonCode;
                        _this.poSaveBasicParam.legalPersonName = _this.changePOForm.poLegalPersonName;
                        _this.poSaveBasicParam.status = _this.changePOForm.status;
                        _this.poSaveBasicParam.contractNo = _this.changePOForm.contractNo;
                        _this.poSaveBasicParam.expectTime = _this.changePOForm.expectTime;
                        _this.poSaveBasicParam.sendPlant = _this.changePOForm.sendPlant;
                        _this.poSaveBasicParam.contacts = _this.changePOForm.contacts;
                        _this.poSaveBasicParam.telephone = _this.changePOForm.telephone;
                        _this.poSaveBasicParam.exRate = _this.changePOForm.exRate;
                        _this.poSaveBasicParam.billPeriods = _this.changePOForm.billPeriods;
                        _this.poSaveBasicParam.amount = _this.changePOForm.amount;
                        _this.poSaveBasicParam.totalMoney = _this.changePOForm.totalMoney;
                        _this.poSaveBasicParam.totalMoneyNoTax = _this.changePOForm.totalMoneyNoTax;
                        _this.poSaveBasicParam.currencyTotalMoney = _this.changePOForm.currencyTotalMoney;
                        _this.poSaveBasicParam.currencyTotalMoneyNoTax = _this.changePOForm.currencyTotalMoneyNoTax;
                        _this.poSaveBasicParam.hasSingleAddr = _this.singleDeliveryAddress;  // '仅单一确定的收货地址'
                        _this.poSaveBasicParam.withTaxFlag = _this.changePOForm.withTaxFlag;
                        _this.poSaveBasicParam.remarks = _this.changePOForm.remarks;  // 备注
                        if(_this.receivingInformationDate.length){
                            // _this.poSaveBasicParam.storeRoomCode = _this.storageRoomDate[0].storeRoomCode;
                            _this.poSaveBasicParam.storeRoomCode = _this.receivingInformationDate[0].storeRoomCode;
                        }
                        
                        if(_this.procurementDetailsData.length > 0){
                            if(_this.poSaveBasicParam.hasSingleAddr && !_this.receivingInformationDate.length){
                                _this.common.errorTip("收货明细不能为空！");
                            }else{
                                var tmp={
                                    poSaveBasicParam:_this.poSaveBasicParam,
                                    poSaveItemsParam:_this.procurementDetailsData,
                                    deletedProcurementOrderItems:_this.deletedProcurementOrderItems,
                                };
                                $.ajax({
                                    url:_this.procurement_service+'procurementOrder/submit',
                                    type:'POST',
                                    cache:false,
                                    data:JSON.stringify(tmp),
                                    dataType:'JSON',
                                    contentType:'application/json;charset=utf-8',
                                    success:function(data){
                                        if(data.success){
                                            _this.common.successTip("提交成功！");
                                            _this.$router.push("/SpareOrder");
                                        }else{
                                            _this.common.errorTip(data.errorMessage);
                                        }
                                    }
                                });
                            }
                        }else{
                            _this.common.errorTip("采购明细不能为空！");
                        }
                    } else {
                        _this.common.errorTip("存在未填写的必填项！");
                        return false;
                    }
                });
            },
            // //审核按钮
            // handleReview(){
            //     var _this=this;
            //     _this.handleReviewVisible=true;
            // },
            // toExamine(auditorStatus){   //true 审核通过  false审核不通过
            //     var _this = this;
            //     $.ajax({
            //         url:_this.procurement_service+'procurementOrder/review?orderCode='+_this.changePOForm.prOrderCode+'&approve='+auditorStatus,
            //         type:'POST',
            //         cache:false,
            //         // data:JSON.stringify(tmp),
            //         dataType:'JSON',
            //         contentType:'application/json;charset=utf-8',
            //         success:function(data){
            //             if(data.success){
            //                 _this.common.successTip("操作成功！");
            //                 _this.$router.push("/SpareOrder");
            //             }else{
            //                 _this.common.errorTip(data.errorMessage);
            //             }
            //         }
            //     })
            // },
            // // 审批按钮
            // handleApprove(){
            //     var _this=this;
            //     _this.handleApprovalVisible=true;
            // },
            // examinationAndApproval(approverStatus){ //1 审批通过  0审批不通过
            //     var _this = this;
            //     $.ajax({
            //         url:_this.procurement_service+'procurementOrder/examineApprove?orderCode='+_this.changePOForm.prOrderCode+'&approve='+approverStatus,
            //         type:'POST',
            //         cache:false,
            //         // data:JSON.stringify(tmp),
            //         dataType:'JSON',
            //         contentType:'application/json;charset=utf-8',
            //         success:function(data){
            //             if(data.success){
            //                 _this.common.successTip("操作成功！");
            //                 _this.$router.push("/SpareOrder");
            //             }else{
            //                 _this.common.errorTip(data.errorMessage);
            //             }
            //         }
            //     })
            // },
            // // 作废
            // handleRemove(){
            //     var _this=this;
            //      $.ajax({
            //         url:_this.procurement_service+'procurementOrder/remove?orderCode='+_this.changePOForm.prOrderCode,
            //         //+'&approve='
            //         type:'POST',
            //         cache:false,
            //         // data:JSON.stringify(tmp),
            //         dataType:'JSON',
            //         contentType:'application/json;charset=utf-8',
            //         success:function(data){
            //             if(data.success){
            //                 _this.common.successTip("操作成功！");
            //                 _this.$router.push("/SpareOrder");
            //             }else{
            //                 _this.common.errorTip(data.errorMessage);
            //             }
            //         }
            //     })
            // },
            //待询价明细 每行的删除按钮
            handleDel(index,row){
                var _this=this;
                _this.procurementDetailsData.splice(index,1);
                _this.deletedProcurementOrderItems.push(row.prOrderItemId);
                _this.calTotalMoney(); //采购含税总金额、采购不含税金额
                _this.inputExRate(); // 表单中的本币含税总金额 = 总金额 * 汇率
            },
            
            // // ===================================
            // successTip(p) {     //成功时的提示信息
            //     this.$notify({
            //         title: '成功',
            //         message: p,
            //         type: 'success'
            //     });
            // },
            // errorTip(p) {     //错误提示
            //     this.$notify.error({
            //         title: '错误',
            //         message: p
            //     });
            // }

        }
    }
</script>
